package com.mjk.common.web.getway.restful.interceptor.type.commons.impl;

import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.tools.interceptor.InterceptorChain;
import com.mjk.common.web.getway.restful.interceptor.GetWayInterceptorReq;
import com.mjk.common.web.getway.restful.interceptor.annotation.BeeGetWayInterceptor;
import com.mjk.common.web.getway.restful.interceptor.type.GetWayInterceptor;
import com.mjk.common.web.getway.restful.interceptor.type.GetWayInterceptorType;

@BeeGetWayInterceptor(value = 4, interceptorType = {GetWayInterceptorType.ALL})

public class GetWayCorsInterceptor implements GetWayInterceptor {
    @Override
    public BeeResponse interceptor(GetWayInterceptorReq request, InterceptorChain<GetWayInterceptorReq, BeeResponse> next) {
        // 设置允许跨域的来源
        request.getResponse().setHeader("Access-Control-Allow-Origin", "*");
        // 设置允许的方法（GET, POST, PUT, DELETE等）
        request.getResponse().setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        // 设置允许的头信息
        request.getResponse().setHeader("Access-Control-Allow-Headers", "*");
        // 设置预检请求的有效期
        request.getResponse().setHeader("Access-Control-Max-Age", "3600");
        return next.proceed(request);
    }
}
